#include "vlmagicwandcontextwidget.h"

VLMagicWandContextWidget::VLMagicWandContextWidget(QWidget *parent) :
    VLContextWidget(parent)
{
    layout = setupLayout();
    nameLabel = createAndAddLabel(layout, tr("MAGIC WAND"));

    contiguousToggle = createCheckBox(layout, tr("Contiguous"));
    connect(contiguousToggle, SIGNAL(toggled(bool)), this, SLOT(setContiguous(bool)));

    createAndAddLabel(layout, tr("R:"));
    redTol = createAndAddSpinBox(layout, 0, 100);
    connect(redTol, SIGNAL(valueChanged(int)), this, SLOT(setRed(int)));
    createAndAddLabel(layout, tr("G:"));
    greenTol = createAndAddSpinBox(layout, 0, 100);
    connect(greenTol, SIGNAL(valueChanged(int)), this, SLOT(setGreen(int)));
    createAndAddLabel(layout, tr("B:"));
    blueTol = createAndAddSpinBox(layout, 0, 100);
    connect(blueTol, SIGNAL(valueChanged(int)), this, SLOT(setBlue(int)));

    QStringList *strings = new QStringList();
    *strings << tr("New") << tr("Add") << tr("Subtract");
    actions = createAndAddComboBox(layout, strings);
    connect(actions, SIGNAL(currentIndexChanged(int)), this, SLOT(setAction(int)));

    setDefaults();
}

void VLMagicWandContextWidget::setDefaults() {
    contiguousToggle->setChecked(TOOL_MAGIC_BRUSH->checkContiguity());
    redTol->setValue(TOOL_MAGIC_BRUSH->getColourTolerance(MagicBrushTool::RED));
    greenTol->setValue(TOOL_MAGIC_BRUSH->getColourTolerance(MagicBrushTool::GREEN));
    blueTol->setValue(TOOL_MAGIC_BRUSH->getColourTolerance(MagicBrushTool::BLUE));
    actions->setCurrentIndex(TOOL_MAGIC_BRUSH->getAction() - 1);
}

void VLMagicWandContextWidget::setContiguous(bool b) {
    TOOL_MAGIC_BRUSH->toggleContiguous(b);
}

void VLMagicWandContextWidget::setRed(int val) {
    TOOL_MAGIC_BRUSH->setColourTolerance(MagicBrushTool::RED, val);
}

void VLMagicWandContextWidget::setGreen(int val) {
    TOOL_MAGIC_BRUSH->setColourTolerance(MagicBrushTool::GREEN, val);
}

void VLMagicWandContextWidget::setBlue(int val) {
    TOOL_MAGIC_BRUSH->setColourTolerance(MagicBrushTool::BLUE, val);
}

void VLMagicWandContextWidget::setAction(int val) {
    MagicBrushTool::ACTION a = MagicBrushTool::ACTION(val + 1);
    TOOL_MAGIC_BRUSH->setAction(a);
}
